var fs = require("fs");
var _ = require("lodash");

let fileNameC = "WeaponConfig";
let fileName1 = "WeaponDes";
let fileName2 = "./data/skill4";
let outputFileName = "./data/weapon.json";

let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString()).map;
let WeaponDes = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString()).map;
let skillDes = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString());

let WeaponDesMap = new Map();
let skillMap = new Map();
_.forEach(WeaponDes, (e) => {
  let id = e.id;
  let data = e.data;
  WeaponDesMap.set(id, data);
});
_.forEach(skillDes, (e) => {
  let id = e.id;
  let data = e.data;
  skillMap.set(id, data);
});
_.forEach(mainData, (e) => {
  _.forEach(e.data.weaponStageConfig, (x) => {
    if (skillMap.has(x.weaponLb1)) {
      _.assign(x, skillMap.get(x.weaponLb1));
    }
  });
  e.data.display = _.map(e.data.display, (x) => {
    if (WeaponDesMap.has(x)) {
      return WeaponDesMap.get(x);
    }
    return x;
  })
});

fs.writeFileSync(outputFileName, JSON.stringify(mainData));
